package org.springblade.modules.system.service.impl;

import org.springblade.modules.system.entity.Computer;
import org.springblade.modules.system.mapper.ComputerMapper;
import org.springblade.modules.system.service.ComputerService;
import org.springblade.modules.system.utils.BusinessException;
import org.springblade.modules.system.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ComputerServiceImpl implements ComputerService {

	@Autowired
	private ComputerMapper computerMapper;

	@Override
	public PageBounds<Computer> openComputerTable(Computer computer, int currentPage, int pageSize) throws Exception {
		final int totalSize = computerMapper.countByExample(computer);
		PageBounds<Computer> pageBounds = new PageBounds<Computer>(currentPage, totalSize, pageSize);
		List<Computer> list = computerMapper.selectByLimitPage(computer, pageBounds.getOffset(), pageBounds.getPageSize());
		pageBounds.setPageList(list);
		return pageBounds;
	}

	@Override
	public List<Computer> getAllComputerType(Computer computer) {
		return computerMapper.getAllComputerType(computer);
	}

	@Override
	public PageBounds<Computer> selectByName(Computer computer) {
		final int totalSize = computerMapper.countByExample(computer);
		PageBounds<Computer> pageBounds = new PageBounds<Computer>(computer);
		List<Computer> list = computerMapper.selectByName(computer,totalSize);
		pageBounds.setPageList(list);
		return pageBounds;
	}

	@Override
	public int deleteComputerById(Integer id) {

		return computerMapper.deleteComputerById(id);
	}

	@Override
	public void deleteComputerByIds(List<Integer> ids) {
		computerMapper.deleteComputerByIds(ids);
	}

	@Override
	public int addComputer(Computer computer) {
		try {
			return computerMapper.addComputer(computer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	@Override
	public int updateComputer(Computer computer) {
		return computerMapper.updateComputer(computer);
	}

	@Override
	public Computer findById(Integer id) {
		List<Computer> list = (List<Computer>) computerMapper.findById(id);
		return (Computer) list;
	}
}
